package com.guofen.controller.sjq;

import com.guofen.pojo.SjqSolidliquidProduceElectricity;
import com.guofen.pojo.SjqSolidliquidProduceFault;
import com.guofen.service.sjq.SjqSolidliquidProduceFaultService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "SjqSolidliquidProduceFaultController",description = "固液分离生产现场故障记录表")
public class SjqSolidliquidProduceFaultController {
    @Resource
    private SjqSolidliquidProduceFaultService solidliquidProduceFaultService;

    @ApiOperation("提交固液分离生产现场故障记录")
    @PostMapping("/sjq/SolidliquidProduceFault/add")
    public Result add(@RequestParam("fillTime") String fillTime,@RequestParam("equipmentName") String equipmentName,@RequestParam("faultTime") String faultTime,@RequestParam("operator") String operator,@RequestParam("faultContent") String faultContent,
                      @RequestParam("serviceTimeStart") String serviceTimeStart,@RequestParam("serviceTimeEnd") String serviceTimeEnd,
                      @RequestParam("servicemanInCharge") String servicemanInCharge,@RequestParam("serviceman") String serviceman,@RequestParam("faultReason") String faultReason,
                      @RequestParam("serviceMethod") String serviceMethod,@RequestParam("proposer") String proposer,@RequestParam("recoverTime") String recoverTime,
                      @RequestParam("inspector") String inspector){
        if (solidliquidProduceFaultService.addForm(fillTime,equipmentName,faultTime,operator,faultContent,serviceTimeStart,serviceTimeEnd,servicemanInCharge,serviceman,faultReason,serviceMethod,proposer,recoverTime,inspector)){
            System.out.println("成功");
            return ResultGenerator.genSuccessResult("成功");
        }else {
            return ResultGenerator.genFailResult("保存失败");
        }
    }
    @ApiOperation("获取当日最新一条记录")
    @GetMapping("/sjq/SolidliquidProduceFault/getlast")
    public Result getlast(){
        return ResultGenerator.genSuccessResult(solidliquidProduceFaultService.findForm());
    }

    @ApiOperation("根据 设备名称 获取故障记录")
    @RequestMapping(value = "/sjq/SolidliquidProduceFault/getLastByEquipmentName", method = RequestMethod.POST)
    @ResponseBody
    public Result getLastByEquipmentName(
            @ApiParam(name="equipmentName",value="设备名称",required=true) @RequestParam String equipmentName) {
        return ResultGenerator.genSuccessResult(solidliquidProduceFaultService.getLastByEquipmentName(equipmentName));
    }

    @ApiOperation("填写故障记录 前半")
    @RequestMapping(value = "/sjq/SolidliquidProduceFault/addFrontPart", method = RequestMethod.POST)
    @ResponseBody
    public Result addFrontPart(@ApiParam(name="equipmentName",value="设备名称",required=true) @RequestParam String equipmentName,
                               @ApiParam(name="faultTime",value="故障停机时间",required=true) @RequestParam String faultTime,
                               @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator,
                               @ApiParam(name="faultContent",value="故障情况描述",required=true) @RequestParam String faultContent) {
        return ResultGenerator.genSuccessResult(solidliquidProduceFaultService.addFrontPart(equipmentName,faultTime,operator,faultContent));
    }

    @ApiOperation("填写故障记录 后半")
    @RequestMapping(value = "/sjq/SolidliquidProduceFault/addAfterPart", method = RequestMethod.POST)
    @ResponseBody
    public Result addAfterPart(@ApiParam(name="faultId",value="故障记录ID",required=true) @RequestParam Integer faultId,
                               @ApiParam(name="serviceTimeStart",value="维修开始时间",required=true) @RequestParam String serviceTimeStart,
                               @ApiParam(name="serviceTimeEnd",value="维修结束时间",required=true) @RequestParam String serviceTimeEnd,
                               @ApiParam(name="servicemanInCharge",value="维修负责人",required=true) @RequestParam String servicemanInCharge,
                               @ApiParam(name="serviceman",value="维修人员名字",required=true) @RequestParam String serviceman,
                               @ApiParam(name="faultReason",value="故障原因分析",required=true) @RequestParam String faultReason,
                               @ApiParam(name="serviceMethod",value="维修方法",required=true) @RequestParam String serviceMethod,
                               @ApiParam(name="proposer",value="维修方法提出人",required=true) @RequestParam String proposer,
                               @ApiParam(name="recoverTime",value="故障回复时间·",required=true) @RequestParam String recoverTime,
                               @ApiParam(name="inspector",value="检查人",required=true) @RequestParam String inspector) {
        return ResultGenerator.genSuccessResult(solidliquidProduceFaultService.addAfterPart(faultId,serviceTimeStart,serviceTimeEnd,
                servicemanInCharge,serviceman,faultReason,serviceMethod,proposer,recoverTime,inspector));
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/sjq/SolidliquidProduceFault/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(solidliquidProduceFaultService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/sjq/SolidliquidProduceFault/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="id",required=true) @RequestParam(required = true) Integer id,
                         @ApiParam(name="fill_time",value="fill_time",required=false) @RequestParam(required = false) String fill_time,
                         @ApiParam(name="equipment_name",value="equipment_name",required=false) @RequestParam(required = false) String equipment_name,
                         @ApiParam(name="operator",value="operator",required=false) @RequestParam(required = false) String operator,
                         @ApiParam(name="fault_content",value="fault_content",required=false) @RequestParam(required = false) String fault_content,
                         @ApiParam(name="service_time_start",value="service_time_start",required=false) @RequestParam(required = false) String service_time_start,
                         @ApiParam(name="service_time_end",value="service_time_end",required=false) @RequestParam(required = false) String service_time_end,
                         @ApiParam(name="serviceman_in_charge",value="serviceman_in_charge",required=false) @RequestParam(required = false) String serviceman_in_charge,
                         @ApiParam(name="serviceman",value="serviceman",required=false) @RequestParam(required = false) String serviceman,
                         @ApiParam(name="fault_reason",value="fault_reason",required=false) @RequestParam(required = false) String fault_reason,
                         @ApiParam(name="service_method",value="service_method",required=false) @RequestParam(required = false) String service_method,
                         @ApiParam(name="proposer",value="proposer",required=false) @RequestParam(required = false) String proposer,
                         @ApiParam(name="recover_time",value="recover_time",required=false) @RequestParam(required = false) String recover_time,
                         @ApiParam(name="inspector",value="inspector",required=false) @RequestParam(required = false) String inspector
    ) {
        SjqSolidliquidProduceFault record = new SjqSolidliquidProduceFault();
        record.setId(id);
        record.setFillTime(fill_time);
        record.setEquipmentName(equipment_name);
        record.setOperator(operator);
        record.setFaultContent(fault_content);
        record.setServiceTimeStart(service_time_start);
        record.setServiceTimeEnd(service_time_end);
        record.setServicemanInCharge(serviceman_in_charge);
        record.setServiceman(serviceman);
        record.setFaultReason(fault_reason);
        record.setServiceMethod(service_method);
        record.setProposer(proposer);
        record.setRecoverTime(recover_time);
        record.setInspector(inspector);

        return ResultGenerator.genSuccessResult(solidliquidProduceFaultService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/sjq/SolidliquidProduceFault/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间(时间戳：毫秒)",required = false) @RequestParam(required = false) Long startTime,
                         @ApiParam(name="endTime",value="截止时间(时间戳：毫秒)", required = false) @RequestParam(required = false) Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(solidliquidProduceFaultService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(solidliquidProduceFaultService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
